/****************************************************************************
*					DataSet
*
*	Description:	A class for representing DataSet and methods for working 
*					with it
*
****************************************************************************/

#ifndef _DataSet_H
#define _DataSet_H

#include <vector>
#include "Environment.h"
#include "Feature.h"

class DataSet {
  private:

  protected:

	// Type defenition (for simplifying the code)
	typedef boost::tokenizer<boost::char_separator<char> >	token_separator;

  public:

	/* Data */
	  // Original DataSet
	std::vector< std::vector<unsigned int> > data;
	  // A binary representation for each feature
	std::vector< std::vector< std::vector <unsigned __int32> > > dataPerFeature;
	  // Maximum values of each variable
	std::vector< unsigned int > maxValues;
	  // Number of samples in data set
	unsigned int numOfSamples;
 

	/* Functions */
	  // Standard constructor
	DataSet(void);
      
	  // Standard destructor - empty one
    ~DataSet();

	  // Reads dataSet from file that is indicated in the config-file
	int readDataSet (Environment& environment);

	  // Reads dataSet from file that with a given path
	int readDataSet (const std::string& fileName);

	  // Generate per individual feature presentation
	int fillDataPerFeature (void);

	  // Removes all elements in the data set
	void clear (void);

	  // Sets the maximum value of each variable
	inline int getMaxValues(void);

	  // Return empirical prbability of a given feature in the data set
	float calculateEmpiricalProb (const Feature& feature, const std::vector<unsigned int>& varIDs) const;

	  // Return empirical prbability of a given feature (defined as a description of the simple feature) in the data set
	float calculateEmpiricalProb (const std::vector <std::pair<unsigned int, unsigned int> >& featureDescr, const unsigned int& featureDescrSize) const;

	  // Moves a given proportion of this data set samples to the new data set
	int divideIntoTwo (DataSet& newDataSet, const double& proportion);

	  // Returns sum of 1's in bit representation of a given number u
	static inline unsigned int bitSum(unsigned __int32& u) {
		unsigned __int32 uCount;
		uCount = u - ((u >> 1) & 033333333333) - ((u >> 2) & 011111111111);
		return (unsigned int) (((uCount + (uCount >> 3)) & 030707070707) % 63);}
	  
	  // Returns sum of 1's in bit representation of numbers in a given vector
	static inline unsigned int bitSum(std::vector<unsigned __int32>& v) {
		unsigned int res = 0;
		for (unsigned int i = 0; i < v.size(); i++)
			res += bitSum(v[i]);
		return res;	}
	
}; // end of class

#endif // _DataSet_H
